package com.anjie.powerproject.strategy.repository;

import com.anjie.powerproject.strategy.pojo.DayWeather;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.Date;
import java.util.List;

public interface DayWeatherForecastRepository extends JpaRepository<DayWeather, Integer> {

    @Query(nativeQuery = true, value = "select * from weather_forecast_daily where DATE_FORMAT(sdate,'%Y-%m-%d') = DATE_FORMAT(?1,'%Y-%m-%d') and historycity_code = ?2")
    DayWeather getForecastDayWeatherByDate(Date date,String cityCode);

    @Query(nativeQuery = true, value = "select * from weather_forecast_daily where date_format(sdate, '%Y-%m-%d') >= date_format(date_sub(now(), interval 5 day), '%Y-%m-%d') and date_format(sdate, '%Y-%m-%d') <=  date_format(date_add(now(), interval 10 day), '%Y-%m-%d') and historycity_code=?1 order by sdate asc")
    List<DayWeather> getForecastDayWeatherByAddrCode(String addrCode);

    @Query(nativeQuery = true, value = "select * from weather_forecast_daily where date_format(sdate, '%Y-%m-%d') >= date_format(date_sub(?2, interval 5 day), '%Y-%m-%d') and date_format(sdate, '%Y-%m-%d') <=  date_format(date_add(?2, interval 10 day), '%Y-%m-%d') and historycity_code=?1")
    List<DayWeather> getForecastDayWeatherByAddrCode2(String addrCode, Date time);

    @Query(nativeQuery = true, value = "select * from weather_forecast_daily where historycity_code = :addr and sdate >= :start and sdate < :end")
    List<DayWeather> getForecastDayWeatherByDateList(@Param("addr") String addrCode, @Param("start") String startTime, @Param("end") String endTime);
}
